import java.awt.*;
import java.awt.event.*;

public class ex7_extra2 implements ActionListener, ItemListener{
	Frame frame;
	Label label0,label1;
	Canvas imgCanvas;
	Button bt0,bt1;
	List list;
	
	public ex7_extra2(){
		frame = new Frame("리스트에서 결정된 내용 이미지 캔버스에 반영");
		list = new List(3,false);
		list.add("천안(초록색)");
		list.add("당진(노란색)");
		list.add("속초(파란색)");
	
		
		label1= new Label("이미지 캔버스:");
		imgCanvas = new Canvas();
		imgCanvas.setBackground(Color.green);
		imgCanvas.setSize(200,150);
		label0 = new Label("종료 버튼:");
		bt0 = new Button("종료");
	}
	public void startFrame(){
		frame.setLayout(new FlowLayout());
		frame.add(list);
		frame.add(label1);
		
		bt0.addActionListener(this);
		list.addItemListener(this);
		frame.setSize(500,300);
		
		frame.setVisible(true);
		frame.add(imgCanvas);
		
	
		frame.add(label0);
		frame.add(bt0);
	}
	//public void itemStateChaged(ItemEvent e){
		
		//String str = e.getItem();
		/*
			*/
	//}
	public static void main(String[] args){
		ex7_extra2 pr = new ex7_extra2();
		pr.startFrame();
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String str = e.getActionCommand();
		if(str.equals("종료")) System.exit(0);

		
	}
	@Override
	public void itemStateChanged(ItemEvent e) {
		//System.out.println(e.getItem().toString().length());
		if(e.getItem().toString().equals("0")){
			imgCanvas.setBackground(Color.green);
		}
		else if(e.getItem().toString().equals("1")){
			imgCanvas.setBackground(Color.yellow);
		}
		else if(e.getItem().toString().equals("2")){
			imgCanvas.setBackground(Color.blue);
		}
		else System.out.println("not matched");
		imgCanvas.repaint();
		
		//System.out.print(e.getItem());
		//System.out.println(e.getItem().toString());
		// TODO Auto-generated method stub
		
	}
}